wrote a comment describing why a hash node's key should not also get
authorTim Janik <timj@gtk.org>
Tue, 2 Jun 1998 01:11:17 +0000 (01:11 +0000)
committerTim Janik <timj@src.gnome.org>
Tue, 2 Jun 1998 01:11:17 +0000 (01:11 +0000)
Mon Jun  1 04:43:27 1998  Tim Janik  <timj@gtk.org>

        * ghash.c (g_hash_table_insert): wrote a comment describing why
        a hash node's key should not also get replaced when overriding
        previous entries.

Tue May 26 18:30:06 1998  Tim Janik  <timj@gtk.org>

        * glib.h (g_string_sized_new): new function to controll the preallocated
        size of a GString.

        * glib.h (g_strreversed): new function to reverse a string.

glib/ChangeLog
glib/ghash.c
glib/glib.h
glib/gscanner.c
glib/gstring.c
glib/gutils.c

index 247319f3e97034096c133497e63e5c0fcc0d81d4..907b5455c27a3aed6e87af3b4f09da05be73068e 100644 (file)
@@ -1,3 +1,16 @@
+Mon Jun  1 04:43:27 1998  Tim Janik  <timj@gtk.org>
+
+       * ghash.c (g_hash_table_insert): wrote a comment describing why
+       a hash node's key should not also get replaced when overriding
+       previous entries.
+
+Tue May 26 18:30:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h (g_string_sized_new): new function to controll the preallocated
+       size of a GString.
+
+       * glib.h (g_strreversed): new function to reverse a string.
+
 Mon May 18 22:14:39 1998  Owen Taylor  <otaylor@gtk.org>
 (Yasuhiro SHIRASAKI <joke@awa.tohoku.ac.jp> : gtk-joke-980517-0.patch)
        
index 6b2e50f1f8c7596813b003c0a90d9973148dc96a..90ee2afea8bac8d4a6890bf0d7135ee57bd06cb5 100644 (file)
@@ -122,6 +122,13 @@ g_hash_table_insert (GHashTable *hash_table,
               (* rhash_table->key_compare_func) (node->key, key)) ||
              (node->key == key))
            {
+             /* do not reset node->key in this place, keeping
+              * the old key might be intended.
+              * a g_hash_table_remove/g_hash_table_insert pair
+              * can be used otherwise.
+              *
+              * node->key = key;
+              */
              node->value = value;
              return;
            }
index 4e3dce215e95e646ab732fdac1c5ba65d31634c9..78688c5fbe69afcb5d21a84c26c45e022ed8b59e 100644 (file)
@@ -752,6 +752,7 @@ gint    g_strcasecmp                (const gchar *s1,
                                 const gchar *s2);
 void    g_strdown              (gchar       *string);
 void    g_strup                (gchar       *string);
+void    g_strreverse                   (gchar       *string);
 guint   g_parse_debug_string   (const gchar *string, 
                                 GDebugKey   *keys, 
                                 guint        nkeys);
@@ -795,6 +796,7 @@ gchar*            g_string_chunk_insert_const  (GStringChunk *chunk,
 /* Strings
  */
 GString* g_string_new      (const gchar *init);
+GString* g_string_sized_new (guint       dfl_size);
 void    g_string_free      (GString     *string,
                             gint         free_segment);
 GString* g_string_assign    (GString     *lval,
@@ -1060,6 +1062,8 @@ void              g_scanner_foreach_symbol        (GScanner       *scanner,
                                                 gpointer        func_data);
 void           g_scanner_remove_symbol         (GScanner       *scanner,
                                                 const gchar    *symbol);
+void           g_scanner_freeze_symbol_table   (GScanner       *scanner);
+void           g_scanner_thaw_symbol_table     (GScanner       *scanner);
 void           g_scanner_unexp_token           (GScanner       *scanner,
                                                 GTokenType     expected_token,
                                                 const gchar    *identifier_spec,
index d8f7f6805a555a2ba7c869240bb1b521b7f2027b..56f621ea356b2dda7ef5612e2d835f2f31705531 100644 (file)
@@ -347,8 +347,8 @@ g_scanner_add_symbol (GScanner              *scanner,
 {
   register GScannerHashVal     *hash_val;
   
-  g_return_if_fail (symbol != NULL);
   g_return_if_fail (scanner != NULL);
+  g_return_if_fail (symbol != NULL);
   
   hash_val = g_scanner_lookup_internal (scanner, symbol);
   
@@ -429,6 +429,8 @@ g_scanner_remove_symbol (GScanner   *scanner,
 {
   register GScannerHashVal     *hash_val;
   
+  g_return_if_fail (scanner != NULL);
+
   hash_val = g_scanner_lookup_internal (scanner, symbol);
   
   if (hash_val)
@@ -439,6 +441,22 @@ g_scanner_remove_symbol (GScanner  *scanner,
     }
 }
 
+void
+g_scanner_freeze_symbol_table (GScanner *scanner)
+{
+  g_return_if_fail (scanner != NULL);
+
+  g_hash_table_freeze (scanner->symbol_table);
+}
+
+void
+g_scanner_thaw_symbol_table (GScanner *scanner)
+{
+  g_return_if_fail (scanner != NULL);
+
+  g_hash_table_thaw (scanner->symbol_table);
+}
+
 GTokenType
 g_scanner_peek_next_token (GScanner    *scanner)
 {
index 91a5e1e2c9f5c20809dfaba16c156c661e695f8f..df3fdb500939259a5274dcdbf9d353cfa93223ff 100644 (file)
@@ -205,7 +205,7 @@ g_string_maybe_expand (GRealString* string, gint len)
 }
 
 GString*
-g_string_new (const gchar *init)
+g_string_sized_new (guint dfl_size)
 {
   GRealString *string;
 
@@ -216,16 +216,29 @@ g_string_new (const gchar *init)
 
   string = g_chunk_new (GRealString, string_mem_chunk);
 
-  string->alloc = 2;
+  string->alloc = 0;
   string->len   = 0;
-  string->str   = g_new0(char, 2);
+  string->str   = NULL;
 
-  if (init)
-    g_string_append ((GString*)string, init);
+  g_string_maybe_expand (string, MAX (dfl_size, 2));
+  string->str[0] = 0;
 
   return (GString*) string;
 }
 
+GString*
+g_string_new (const gchar *init)
+{
+  GString *string;
+
+  string = g_string_sized_new (2);
+
+  if (init)
+    g_string_append (string, init);
+
+  return string;
+}
+
 void
 g_string_free (GString *string,
               gint free_segment)
index c97f408bf4a6aa27172158747bc4905b19bbae97..321501827abbc6ffc9013757d52d76f8b059f716 100644 (file)
@@ -731,6 +731,31 @@ g_strup (gchar  *string)
     }
 }
 
+void
+g_strreverse (gchar       *string)
+{
+  g_return_if_fail (string != NULL);
+
+  if (*string)
+    {
+      register gchar *h, *t;
+
+      h = string;
+      t = string + strlen (string) - 1;
+      
+      while (h < t)
+       {
+         register gchar c;
+         
+         c = *h;
+         *h = *t;
+         h++;
+         *t = c;
+         t--;
+       }
+    }
+}
+
 gint
 g_strcasecmp (const gchar *s1,
              const gchar *s2)